﻿@{
    Bundle("jquery_validate");
}

<table>
    <tr>
        <td style="min-width: 200px; vertical-align: top;">
            <fieldset class="groupbox">
                <section>
                    <script type="text/javascript">
                        jQuery(document).ready(function () {
                            jQuery.ajax({
                                type: 'post',
                                url: '@Url.Action(Loc.Act("List").Ctrl("Permission"))',
                                dataType: 'json',
                                success: function (rsp) {
                                    var ddl = jQuery('@ID("#ddl_permission")');
                                    ddl.empty();
                                    jQuery.each(rsp, function (k, v) {
                                        ddl.append('<option value=' + v.id + '>' + v.value + '</option>');
                                    });
                                }
                            });
                        });
                    </script>
                    <form id="@ID("form")" action="@Url.Action(Loc.Act("Map").Ctrl("Relation").NoArea())" method="post">
                        <input type="hidden" name="operation" value="MapPermissionToRole" />
                        <input type="hidden" name="returnUrl" value="@Request.RawUrl" />
                        <input type="hidden" name="entityID" value="@JDM.Int32(Model.EntityID)" />
                        <ul>
                            <li>
                                <select id="@ID("ddl_permission")" name="childID"></select>
                            </li>
                        </ul>
                        <ul class="bar toolbar">
                            <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
                        </ul>
                    </form>
                </section>
            </fieldset>
        </td>
        <td style="width: 100%; vertical-align: top;">
            <ul class="cloud">
            @foreach(var i in Model.Permissions)
            {
                <li>
                    <ul class="bar inlinebar">
                        <li><a href="@Url.Action(Loc.Act("Edit").Ctrl("Permission").Set(new
                        {
                            id = JDM.Int32(i.EntityID)
                        }))">&crarr;</a></li>
                        <li><a class="confirm" href="@Url.Action(Loc.Act("Unmap").Ctrl("Relation").NoArea().Set(new
                        {
                            operation = "UnmapPermissionFromRole",
                            returnUrl = Request.RawUrl,
                            entityID = JDM.Int32(Model.EntityID), 
                            childID = JDM.Int32(i.EntityID)
                        }))">x</a></li>
                    </ul>
                    @JDM.String(i.Code)
                </li>
            }
            </ul>
        </td>
    </tr>
</table>